package xinyu.customer.login.data;

import com.logos.common.source.network.entity.BaseNetEntity;

import xinyu.customer.bean.UserEntity;

public class LoginPresenter implements LoginContract.Presenter {

    private LoginContract.View mView;
    private LoginDataSource mDataSource;

    public LoginPresenter(LoginContract.View view, LoginDataSource dataSource) {

        if (view == null || dataSource == null) {
            throw new IllegalArgumentException("view and dataSource must not be empty");
        }

        mView = view;
        mDataSource = dataSource;
        view.setPresenter(this);
    }

    @Override
    public void getLoginList(String phoneNum, String password) {
        mView.showLoading();
        mDataSource.getLoginData(phoneNum, password, new LoginDataSource.LoginCallback() {
            @Override
            public void onLoginComplete(BaseNetEntity<UserEntity> result) {
                mView.hideLoading();
                mView.onLoginSuccess(result);
            }

            @Override
            public void onFailed(int errorId, String errorMessage) {
                mView.hideLoading();
                mView.showMessage(errorMessage);
            }
        });
    }

    @Override
    public void create() {

    }

    @Override
    public void destroy() {

    }
}
